#include<iostream>
#include<vector>
#include "bintree.h"
using namespace std;

void print_level(BinTree root){
    vector<TNode*> vec;
    if(root==NULL)
        return;
    int cur,last;
    cur = 0;
    last = 1;
    vec.push_back(root);
    while(cur < vec.size()){
        last = vec.size();
        while(cur < last){
            printf("%c ",vec[cur]->data);
            if(vec[cur]->left)
                vec.push_back(vec[cur]->left);
            if(vec[cur]->right)
                vec.push_back(vec[cur]->right);
            cur++;
        }
        printf("\n");
    }
}
static int k = 2;

int print_sepcial(BinTree root,int m,int *cnt){
    if(!root || m<0)
        return 0;
    if(m==0){
        if(*cnt == k){
            printf("%c",root->data);
            return 1;
        }
        *cnt += 1;
        return 0;
    }
    return print_sepcial(root->left,m-1,cnt) || print_sepcial(root->right,m-1,cnt);
}

int main(){
    int *cnt = 0;
    BinTree root;
    create_tree(&root);
    re_inorder(root);
    printf("\n");
    //print_level(root);
    print_sepcial(root,2,cnt);
    return 0;
}
